package github.fafaovo.common.item;

import github.fafaovo.common.Itemgroup.ExampleGroup;
import github.fafaovo.deepcapacity;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Food;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.EffectInstance;
import net.minecraft.potion.Effects;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.world.Explosion;
import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

import javax.annotation.Nonnull;
import java.util.List;

public class tntlighter extends Item {
    private static final Food food = (new Food.Builder())
            .saturation(0) //饱腹度
            .hunger(0) //鸡腿
            .setAlwaysEdible() //满饱腹度也能吃
            .fastToEat() //吃的更快
            .build();



    public tntlighter() {
        super(new Properties().group(ExampleGroup.exampleGroup).food(food));
    }

    @Override
    public ItemStack onItemUseFinish(ItemStack stack, World worldIn, LivingEntity entityLiving) {
        if(entityLiving instanceof PlayerEntity)
        {
            entityLiving.addPotionEffect(new EffectInstance(Effects.RESISTANCE,2,5));
            worldIn.createExplosion(null,
                    entityLiving.getPosX(),entityLiving.getPosY(),entityLiving.getPosZ(),
                    5,  //爆炸等级
                    Explosion.Mode.NONE //是否破坏方块
            );
        }
        return super.onItemUseFinish(stack, worldIn, entityLiving);
    }

    //添加提示文本
    @Override
    @OnlyIn(Dist.CLIENT)
    public void addInformation(@Nonnull ItemStack stack, World world, @Nonnull List<ITextComponent> tooltip, @Nonnull ITooltipFlag flag)
    {

        tooltip.add(new TranslationTextComponent(deepcapacity.MOD_ID + ".lighter.text"));
    }
}
